﻿package  {
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import com.greensock.TweenMax;
	import com.greensock.easing.*;
	
	public class playerBlast extends MovieClip {
		
		private var speed:int;
		
		public function playerBlast() {
			speed = 2000;
			addEventListener(Event.ENTER_FRAME, checkForDone);
		}
		
		public function blast(xgoal:int, ygoal:int)
		{
			var dist:Number = Math.sqrt((xgoal*xgoal)+(ygoal*ygoal));
			var time:Number = dist/speed; 
			TweenMax.to(this, time, {x:xgoal,
						y:ygoal, onComplete:BOOM});
		}
		
		public function BOOM():void
		{
			TweenMax.killTweensOf(this);
			
			if(currentFrame < 9)
			{
				gotoAndPlay("FirstDetonate");
			}
			if(currentFrame > 19 && currentFrame < 32)
			{
				gotoAndPlay("SecondDetonate");
			}
			if(currentFrame > 43 && currentFrame < 52)
			{
				gotoAndPlay("ThirdDetonate");
			}
		}
		
		public function checkForDone(e:Event):void
		{
			if(currentFrameLabel == "FirstClean" ||
			   currentFrameLabel == "SecondClean" ||
			   currentFrameLabel == "ThirdClean")
			   {
				   parent.removeChild(this);
				   removeEventListener(Event.ENTER_FRAME, checkForDone);
			   }
		}
		
		
	}
	
}
